home *** CD-ROM | disk | FTP | other *** search
/ Tux Racer / Tux Racer.iso / program files / Sunspire Studios / Tux Racer / courses / common / procs.tcl < prev    next >
Encoding:
Text File  |  2001-08-22  |  4.1 KB  |  145 lines

  1. # Procedures for collision responses
  2.  
  3. proc moveHouse {node player} {
  4.     set pos [objget $node position]
  5.     set pos [lreplace $pos 2 2 [expr {[lindex $pos 2] - 1}]]
  6.     objset $node {-position} $pos
  7. }
  8.  
  9. proc startAnimation {action node player} {
  10.     if { [llength [objget $action children]] == 0 } {
  11.     objcall $action start
  12.     }
  13. }
  14.  
  15.  
  16. proc linkToParentAndCreateAction {anim channel node player} {
  17.     regsub -all : $anim _ underscoreanim 
  18.     regsub -all : $node _ underscorenode 
  19.     set name "${underscorenode}_${underscoreanim}"
  20.  
  21.     if { ![objexists ":actions:tmp"] } {
  22.     objcreate s_container :actions:tmp
  23.     }
  24.  
  25.     if { ![objexists ":actions:tmp:$name"] } {
  26.     set parent [objget $node parent]
  27.  
  28.     # Link the anim to the node
  29.     set current_curves [objget $parent bound_animations]
  30.     objset $parent {-bound_animations} "$current_curves \{\( $anim \, \
  31.         $channel \, 1 \) \} "
  32.  
  33.     # Create the action
  34.     objcreate s_action_anim :actions:tmp:$name \
  35.         {-root_anim} $anim \
  36.         {-root_object} $parent
  37.  
  38.     # Start the action
  39.     objcall :actions:tmp:$name start
  40.     }
  41. }
  42.  
  43. proc autolinkAnimSibling {anim_root node player} {
  44.  
  45.     set parent [objget $node parent]
  46.     set target_node "$parent:anim"
  47.  
  48.     regsub -all : $target_node _ underscorenode 
  49.     regsub -all : $anim_root _ underscoreanim 
  50.     set name "${underscorenode}_${underscoreanim}"
  51.  
  52.     if { ![objexists ":actions:tmp"] } {
  53.     objcreate s_container :actions:tmp
  54.     }
  55.     
  56.     if { [objexists ":actions:tmp:$name"] } {
  57.     return;
  58.     }
  59.  
  60.     set current_curves [objget $target_node bound_animations]
  61.  
  62.     set anim_children [objget $anim_root children]
  63.  
  64.     set channelMap(rotateX) x_rotation
  65.     set channelMap(rotateY) y_rotation
  66.     set channelMap(rotateZ) z_rotation
  67.     set channelMap(translateX) x_translation
  68.     set channelMap(translateY) y_translation
  69.     set channelMap(translateZ) z_translation
  70.     set channelMap(scaleX) x_scale
  71.     set channelMap(scaleY) y_scale
  72.     set channelMap(scaleZ) z_scale
  73.     set channelMap(terrainX) x_terrain
  74.     set channelMap(terrainZ) z_terrain
  75.  
  76.     foreach anim $anim_children {
  77.  
  78.     set curveName [objget $anim basename]
  79.     set channel $channelMap($curveName)
  80.  
  81.     # Link the anim to the node
  82.     lappend current_curves  "\( $anim \, $channel \, 1 \)"
  83.     }
  84.  
  85.     objset $target_node {-bound_animations} $current_curves 
  86.  
  87.     # Create the action
  88.     objcreate s_action_anim :actions:tmp:$name \
  89.         {-root_anim} $anim_root \
  90.         {-root_object} $parent
  91.     
  92.     # Start the action
  93.     objcall :actions:tmp:$name start
  94.  
  95.     # Enable all sounds that are children of $target_node
  96.     enableSounds $target_node $player
  97. }
  98.  
  99. proc enableSounds {node plyr} {
  100.     if { [objcall $node is_a s_sound3dinst] } {
  101.     objset $node -enabled 1
  102.     }
  103.     if { [objcall $node is_a s_container] } {
  104.     foreach child [objget $node children] {
  105.         enableSounds $child $plyr
  106.     }
  107.     }
  108. }
  109.                                                
  110. proc resetPlayer {node plyr} {
  111.     objcall $plyr reset
  112. }
  113.                                                
  114. proc launchPlayer {node plyr} {
  115.     set dir [ objget $node y_vector ]
  116.     set dir [lreplace $dir 0 0 [expr {[lindex $dir 0] * 60}]]
  117.     set dir [lreplace $dir 1 1 [expr {[lindex $dir 1] * 60}]]
  118.     set dir [lreplace $dir 2 2 [expr {[lindex $dir 2] * 60}]]
  119.  
  120.     objcall $plyr accelerate .1 $dir
  121. }
  122.                                                
  123. proc speedPlayer {node plyr} {
  124.     set dir [ objget $node z_vector ]
  125.     set dir [lreplace $dir 0 0 [expr {[lindex $dir 0] * -30}]]
  126.     set dir [lreplace $dir 1 1 [expr {[lindex $dir 1] * -30}]]
  127.     set dir [lreplace $dir 2 2 [expr {[lindex $dir 2] * -30}]]
  128.  
  129.     objcall $plyr accelerate .2 $dir
  130. }
  131.  
  132. proc speedPlayer60 {node plyr} {
  133.     set dir [ objget $node z_vector ]
  134.     set dir [lreplace $dir 0 0 [expr {[lindex $dir 0] * -60}]]
  135.     set dir [lreplace $dir 1 1 [expr {[lindex $dir 1] * -60}]]
  136.     set dir [lreplace $dir 2 2 [expr {[lindex $dir 2] * -60}]]
  137.  
  138.     objcall $plyr accelerate .2 $dir
  139. }
  140.  
  141. proc turning_powerup {node plyr} {
  142.     objcall $plyr set_turn_multiplier 10 5
  143.     objdel $node
  144. }
  145.